package com.ruoyi.shop.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.shop.api.RemoteDrawalService;
import com.ruoyi.shop.api.domain.CheDrawal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;

/**
 * 文件服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteDrawalFallbackFactory implements FallbackFactory<RemoteDrawalService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteDrawalFallbackFactory.class);


    @Override
    public RemoteDrawalService create(Throwable throwable) {
        log.error("商户服务调用失败:{}", throwable.getMessage());
        return new RemoteDrawalService() {

            @Override
            public TableDataInfo list(CheDrawal cheDrawal, String source) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("获取商家提现记录列表失败: " + throwable.getMessage());
                tableDataInfo.setRows(new java.util.ArrayList<>());
                tableDataInfo.setTotal(0);
                return tableDataInfo;
            }

            @Override
            public TableDataInfo listNoPage(CheDrawal cheDrawal) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("获取商家提现记录列表（不分页）失败: " + throwable.getMessage());
                tableDataInfo.setRows(new java.util.ArrayList<>());
                tableDataInfo.setTotal(0);
                return tableDataInfo;
            }

            @Override
            public AjaxResult getInfo(Long drawalId, String source) {
                return AjaxResult.error("通过id获取订单信息失败: " + throwable.getMessage());
            }

            @Override
            public AjaxResult add(CheDrawal cheDrawal, String source) {
                return AjaxResult.error("新增商家提现记录失败: " + throwable.getMessage());
            }

            @Override
            public AjaxResult edit(CheDrawal cheDrawal, String source) {
                return AjaxResult.error("修改商家提现记录失败: " + throwable.getMessage());
            }

            @Override
            public AjaxResult remove(Long[] drawalIds, String source) {
                return AjaxResult.error("删除商家提现记录失败: " + throwable.getMessage());
            }
        };
    }
}
